package com.xaicode.template.activemq.queue;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

public class ProduceQueue {


    public static final String ACTIVEMQ_URL = "tcp://192.168.18.182:61616";
    public static final String QUEUE_NAME = "queue1";

    /**
     * 队列默认发送的是持久化消息
     *
     * @param args
     * @throws JMSException
     */
    public static void main(String[] args) throws JMSException {
        ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(ACTIVEMQ_URL);
        Connection connection = activeMQConnectionFactory.createConnection();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        connection.start();
        Queue queue = session.createQueue(QUEUE_NAME);
        MessageProducer producer = session.createProducer(queue);
        producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
        for (int i = 0; i < 3; i++) {
            TextMessage textMessage = session.createTextMessage();
            textMessage.setText("queue" + i);
            producer.send(textMessage);
        }
        producer.close();
        session.close();
        connection.close();
    }
}
